package com.vonchange.utils.tpl.method;

import java.util.List;

import org.springframework.stereotype.Component;

import com.vonchange.utils.json.JsonUtil;

import freemarker.template.SimpleSequence;
import freemarker.template.TemplateMethodModelEx;
import freemarker.template.TemplateModelException;

@Component
public class ToJsonMethod implements TemplateMethodModelEx{

	@Override
	public Object exec(List arguments) throws TemplateModelException {
		Object bean=arguments.get(0);
		String result=null;
		if(bean instanceof SimpleSequence){
			SimpleSequence beanx=(SimpleSequence) bean;
			 result=JsonUtil.toJson(beanx.toList());
			return result;
		}
		 result=JsonUtil.toJson(bean);
		System.err.println(result);
		// TODO Auto-generated method stub
		return result;
	}


}